<template>
	<el-dialog :visible.sync="options.showDialog" width="700px" class="update">
		<h3>{{options.title}}</h3>
		<el-form ref="Form" :model="form" label-width="100px" class="search searchBox">
			<!-- <el-form-item label="标注类型">
				<el-select v-model="form.arrange" placeholder="请选择标注类型" :disabled="disabled.arrange" clearable>
					<el-option label="已安排" value="1"></el-option>
					<el-option label="等待安排" value="2"></el-option>
				</el-select>
			</el-form-item> -->
			<el-form-item label="姓名" prop="name">
			    <el-input v-model="form.name" placeholder="请输入姓名" :disabled="disabled.name"></el-input>
			</el-form-item>
			<el-form-item label="手机号" prop="telnum">
			    <el-input v-model="form.telnum" placeholder="请输入手机号" :disabled="disabled.telnum"></el-input>
			</el-form-item>
			<el-form-item label="性别" prop="sex">
				<el-select v-model="form.sex" placeholder="请选择性别" :disabled="disabled.sex" clearable>
					<el-option label="男" value="男"></el-option>
					<el-option label="女" value="女"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="年龄" prop="age">
			    <el-input v-model="form.age" placeholder="请输入年龄" :disabled="disabled.age"></el-input>
			</el-form-item>
			<!-- <el-form-item label="学历" prop="education">
			    <el-select v-model="form.education" placeholder="请选择学历" :disabled="disabled.education" clearable>
			    	<el-option v-for="(item,index) in educationList" :label="item" :value="item" :key="index"></el-option>
			    </el-select>
			</el-form-item> -->
			<!-- <el-form-item label="籍贯" prop="nativePlace">
			    <el-input v-model="form.nativePlace" placeholder="请输入籍贯" :disabled="disabled.nativePlace"></el-input>
			</el-form-item> -->
			<el-form-item label="居住地" prop="citys">
				<city-Cascader :disable="disabled.region" :citys="citys" :level="level" @handleChange="handleCityChange"></city-Cascader>
			</el-form-item>
			<el-form-item label="身份证" prop="citys">
				 <el-input v-model="form.cardNum" placeholder="请输入身份证" :disabled="disabled.cardNum"></el-input>
			</el-form-item>
			<el-form-item label="职能" prop="citys">
				 <el-cascader  ref="cascader" v-model="form.tradeCode" :options="workersList" clearable :disabled="disabled.tradeName" @change="handleChangeCode"></el-cascader>
				 
				 
			</el-form-item>
			<el-form-item label="岗位名称" prop="citys">
				 <el-input v-model="form.jobName" placeholder="请输入岗位名称" :disabled="disabled.jobName"></el-input>
			</el-form-item>
			<el-form-item label="期望薪资" prop="citys">
				 <el-input v-model="form.salaryExpectation" placeholder="请输入期望薪资" :disabled="disabled.salaryExpectation"></el-input>
			</el-form-item>
			<el-form-item label="原工作单位" prop="citys">
				 <el-input v-model="form.originalCompany" placeholder="请输入原工作单位" :disabled="disabled.originalCompany"></el-input>
			</el-form-item>
			<el-form-item label="原年薪" prop="citys">
				 <el-input v-model="form.annualSalary" placeholder="请输入原年薪" :disabled="disabled.annualSalary"></el-input>
			</el-form-item>
			<el-form-item label="期望岗位" prop="position">
			    <el-input v-model="form.position" placeholder="请输入期望岗位" :disabled="disabled.position"></el-input>
			</el-form-item>
			<el-form-item label="工作状态" prop="workStatus">
			    <el-select v-model="form.workStatus" placeholder="请选择工作状态" clearable :disabled="disabled.workStatus">
			    	<el-option label="沟通" value="1"></el-option>
			    	<el-option label="通知面试" value="2"></el-option>
			    	<el-option label="实到面试" value="3"></el-option>
			    	<el-option label="通知复试" value="4"></el-option>
			    	<el-option label="实到复试" value="5"></el-option>
			    	<el-option label="录取" value="6"></el-option>
			    	<el-option label="到岗" value="7"></el-option>
			    </el-select>
			</el-form-item>
			<el-form-item label="项目归属" >
				<el-select v-model="form.projectBelongs" placeholder="请选择项目" :disabled="disabled.projectBelongs" clearable @change="getGuishu">
					<el-option v-for="(item,index) in projectList" :label="item.projectBlongs" :value="item.projectBlongs" :key="index"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="招聘渠道" >
				<el-select v-model="form.recruitmentChannel" placeholder="请选择招聘渠道" :disabled="disabled.recruitmentChannel" clearable>
					<el-option v-for="(item,index) in options.recruitmentChannelList" :label="item" :value="item" :key="index"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="面试时间">
				<el-date-picker type="datetime" v-model="form.interviewTime" value-format="yyyy-MM-dd HH:mm" placeholder="请选择面试时间"   :disabled="disabled.interviewTime" >
				</el-date-picker>
			</el-form-item>
		<!-- 	<el-form-item label="入职时间" >
				<el-date-picker :disabled="disabled.hiredate" v-model="form.hiredate" type="date" value-format="yyyy-MM-dd" placeholder="选择日期"></el-date-picker>
			</el-form-item>	
			<el-form-item label="备注" prop="newRemarks">
			    <el-input v-model="form.newRemarks" :disabled="disabled.newRemarks"></el-input>
			</el-form-item> -->
		</el-form>
		<div class="subData">
			<el-button @click="subData" type="primary" size="mini">确认修改</el-button> 
		</div>
	</el-dialog>
</template>

<script>
import cityCascader from "@/component/cityCascader/index.vue";
import cityData from "@/assets/citys.json";
export default{
	components:{
		cityCascader
	},
	props:{
		options:{
			require: true,
			type: Object
		}
	},
	data(){
		return {
			form:{
				arrange: '',								//标注类型
				name: '',									//姓名
				telnum: '',									//手机号
				sex: '',									//性别
				age: '',									//年龄
				education: '',								//学历
				nativePlace: '',							//籍贯
				presentAddress: '',							//现住址
				position: '',								//岗位名称
				workStatus: '',								//工作状态
				projectBelongs: '',							//项目归属
				hiredate: '',								//入职时间
				newRemarks: '',								//备注
				recruitmentChannel:[],
				region:'',
				cardNum:'',
				tradeName:'',
				tradeCode:'',
				jobName:'',
				salaryExpectation:'',
				originalCompany:'',
				originalCity:'',
				annualSalary:'',
				hoppingIntention:'',
			},
			workersList:[],
			citys: [],										//城市列表
			recruitmentChannelList:[],
			level: '0',										//城市等级
			projectList:[],									//项目列表
			educationList: ["不限","初中及以下","高中","中技","中专","大专","本科","硕士","MBA","博士","其他"],
			disabled:{
				arrange: true,								//标注
				name: true,									//姓名
				telnum: true,								//电话号码
				sex: true,									//性别
				age: true,									//年龄
				education: true,							//学历
				nativePlace: true,							//籍贯
				presentAddress: true,						//现住址
				position: true,								//岗位名称
				workStatus: true,							//工作状态
				projectBelongs: true,						//项目归属
				hiredate: true,								//入职时间
				newRemarks: true,							//备注名称
				recruitmentChannel:true,
				region:true,
				cardNum:true,
				tradeName:true,
				jobName:true,
				salaryExpectation:true,
				originalCompany:true,
				originalCity:true,
				annualSalary:true,
			}
		}
	},
	created(){
		this.getSearchList();
		let workers = require('@/assets/mask/positionList.json');
		this.workersList = workers.position; //职能类型
	},
	methods:{
		handleChangeCode(data){
		console.log(data);	
		  console.log(this.$refs["cascader"].getCheckedNodes()[0].label)
		  this.form.tradeName=this.$refs["cascader"].getCheckedNodes()[0].label
		},
		getGuishu(data){
			console.log(data);
			this.$telAxios.get('/v1/librarian/projectBelongsList',{}).then(item=>{
				 
			let dat = item.data.data
			let projectId ='';
			dat.forEach(r=>{
				if(r.projectBlongs==data){
					projectId=r.projectId	
				}
			})
			this.$telAxios.get('/v1/librarian/pecruitmentChannelByProjectId?projectId='+projectId,{}).then(res=>{
				this.options.recruitmentChannelList=res.data.data
				console.log(res);
			})
			
			})
		},
		//获取项目列表
		getProjectList(){
			this.$telAxios.post('/v1/librarian/selectProjectListByProjectName',{}).then(res => {
				console.log(res);
				if(res.data.code === 1000){
					let result = res.data.data;
					this.projectList = result;
				}else{
					this.$message({
						message: res.data.message,
						type: 'warning'
					})
				}
			})
			
			
			
			
			
		},
		getSearchList(mark) {
			let data = {}
			let  url = '/v1/librarian/projectBelongsList'
			this.$telAxios.get(url, data).then(res => {
				this.projectList = res.data.data
			})
		},
		//提交数据
		subData(){
			console.log(this.options.type);
			console.log(this.form[this.options.type]);
			if(!this.form[this.options.type]){
				this.$message({
					message: '被修改的资料不能为空！',
					type: 'warning'
				})
				return false;
			}
			this.$emit('updateData',this.form[this.options.type]);
		},
		//选择城市
		handleCityChange (val) {
			this.citys = val;
			console.log(val);
			this.cityConvert(val);
		},
		//城市转换,将城市编号转换为城市名
		cityConvert(val){
			let citys = cityData.city;
			let str = val[0] + '';
			if(str == 'NaN'){ this.form.presentAddress = '';return false};
			citys.forEach(item => {
				if(item.code === val[0]){
					this.form.presentAddress = item.name;
					item.subLevelModelList.forEach(item1 => {
						if(item1.code === val[1]){
							this.form.presentAddress = this.form.presentAddress + '-' + item1.name;
							item1.subLevelModelList.forEach(item2 => {
								if(item2.code === val[2]){
									this.form.region = this.form.presentAddress + '-' + item2.name;
								}
							})
						}
					})
				}
			})
		},
		//城市转换,将城市名转换为城市编号
		numberConvert(city){
			let arr = city.split('-');
			let citys = cityData.city;
			this.citys = [];
			citys.forEach(item => {
				if(item.name == arr[0]){
					this.citys.push(item.code); 
					item.subLevelModelList.forEach(item1 => {
						if(item1.name == arr[1]){
							this.citys.push(item1.code);
							item1.subLevelModelList.forEach(item2 => {
								if(item2.name == arr[2]){
									this.citys.push(item2.code);
								}
							})
						}
					})
				}
			})
		}
	},
	watch:{
		'options.showDialog'(){
			if(this.options.showDialog){
				this.form = Object.assign({},this.options.userInfo);
				this.disabled[this.options.type] = false;
				// this.numberConvert(this.options.userInfo.presentAddress);
			}else{
				this.disabled = {
					arrange: true,								//标注
					name: true,									//姓名
					telnum: true,								//电话号码
					sex: true,									//性别
					age: true,									//年龄
					education: true,							//学历
					nativePlace: true,							//籍贯
					presentAddress: true,						//现住址
					position: true,								//岗位名称
					workStatus: true,							//工作状态
					projectBelongs: true,						//项目归属
					hiredate: true,								//入职时间
					newRemarks: true,							//备注名称
					recruitmentChannel:true,
					region:true,
					cardNum:true,
					tradeName:true,
					jobName:true,
					salaryExpectation:true,
					originalCompany:true,
					originalCity:true,
					annualSalary:true,
					
				}
			}
		},
	}
}
</script>

<style scoped="scoped">
.update{overflow: hidden;}
.update h3{height: 60px;line-height: 60px;text-align: center;font-size: 16px;border-bottom: 1px solid #D2D2D2;}
.search{width: 600px;margin: 20px auto;overflow-y: scroll;max-height: 500px;padding: 0 40px;}
.subData{text-align: center;padding: 20px 0;}
</style>
